#ifndef __MODBUS_H__
#define __MODBUS_H__
#include<modbus/modbus.h>
void close_fd(int fd);

enum ConnectType
{
    ModbusTcp = 0,
    ModbusUdp = 1,
};
class modbus
{
private:
    modbus_t *m_ctx;
    modbus_mapping_t *m_mapping;
    fd_set m_redset;
    int m_listen_fd;
    ConnectType m_type;
public:
    modbus(const char* address,int port);
    ~modbus();
public:
    void setConnectType(ConnectType type);
    void setMapping(int nb_bits, int nb_input_bits,
                                                int nb_registers, int nb_input_registers);
    int ModbusTcpAccept(int psock,fd_set *rset);
    void Listen();

    void loop();

};



#endif